package com.mia.props.common;

import com.mia.props.Props;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class BlockFake extends BlockContainer {
   public BlockFake() {
      super(Material.cloth);
      this.setHardness(0.25F);
   }

   @SideOnly(Side.CLIENT)
   public void registerBlockIcons(IIconRegister iconregistrar) {
   }

   @SideOnly(Side.CLIENT)
   public IIcon getIcon(int side, int meta) {
      return Blocks.soul_sand.getIcon(side, 0);
   }

   public boolean isOpaqueCube() {
      return false;
   }

   public boolean renderAsNormalBlock() {
      return false;
   }

   public int getRenderType() {
      return -1;
   }

   public TileEntity createNewTileEntity(World world, int meta) {
      return new TileFake();
   }

   public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
      TileEntity tile = Props.getTileEntityPreferNotCreating(world, x, y, z);
      if (tile instanceof TileFake) {
         TileProps master = ((TileFake)tile).getMaster();
         if (master != null) {
            return Props.blockProps.collisionRayTrace(world, master.xCoord, master.yCoord, master.zCoord, origin, direction);
         }
      }

      return super.collisionRayTrace(world, x, y, z, origin, direction);
   }

   public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List list, Entity ent) {
      TileEntity tile = Props.getTileEntityPreferNotCreating(world, x, y, z);
      if (tile instanceof TileFake) {
         TileProps master = ((TileFake)tile).getMaster();
         if (master != null) {
            Props.blockProps.addCollisionBoxesToList(world, master.xCoord, master.yCoord, master.zCoord, mask, list, ent);
         }
      } else {
         super.addCollisionBoxesToList(world, x, y, z, mask, list, ent);
      }

   }

   public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity collidingEntity) {
      TileEntity tile = Props.getTileEntityPreferNotCreating(world, x, y, z);
      if (tile instanceof TileFake) {
         TileProps master = ((TileFake)tile).getMaster();
         if (master != null && master.getModelData().spiderweb) {
            BlockProps.onEntityWebbed(collidingEntity, world);
         }
      }

   }
}
